package com.laxcen.controller2;


import com.github.pagehelper.PageInfo;
import com.laxcen.smoke.config.MyLog;
import com.laxcen.smoke.dto.req.*;
import com.laxcen.smoke.dto.res.*;
import com.laxcen.smoke.entity.PickCode;
import com.laxcen.smoke.service.IssueService;
import com.laxcen.smoke.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;


@Api(tags = "APP管理")
@RestController
@RequestMapping("/issue")
public class IssueController {

    @Autowired
    private IssueService issueService;

    @ApiOperation(value = "APP版本管理添加",notes =
            "请求信息： \n" +
                    "&emsp; versionno &nbsp; : &nbsp; 版本号 \n" +
                    "&emsp; versiondes &nbsp; : &nbsp; 版本描述 \n" +
                    "&emsp; file &nbsp; : &nbsp; 上传文件 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/insert",consumes = "multipart/form-data;")
    @MyLog(operation = "APP版本添加")
//    @RequiresPermissions("issue")
    public Response insert(AddAppVersionReq addAppVersionReq){
//        AddAppVersionReq
        return issueService.insert(addAppVersionReq.getVersionno(), addAppVersionReq.getVersiondes(), addAppVersionReq.getFile());
    }

    @ApiOperation(value = "APP版本管理修改",notes =
            "请求信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; 要修改的版本id \n" +
                    "&emsp; versionno &nbsp; : &nbsp; 版本号 \n" +
                    "&emsp; versiondes &nbsp; : &nbsp; 版本描述 \n" +
                    "&emsp; file &nbsp; : &nbsp; 上传文件 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/update",consumes = "multipart/form-data;")
    @MyLog(operation = "APP版本修改")
//    @RequiresPermissions("issue")
    public Response update(UpdateAppVersionReq updateAppVersionReq){
        return issueService.update(updateAppVersionReq.getId(),updateAppVersionReq.getVersionno(), updateAppVersionReq.getVersiondes(), updateAppVersionReq.getFile());
    }

    @ApiOperation(value = "APP版本管理删除",notes =
            "请求信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/delete")
    @MyLog(operation = "APP版本删除")
    @RequiresPermissions("issue")
    public Response delete(@RequestBody CommonOneIdReq commonOneIdReq){
        return issueService.delete(commonOneIdReq.getId());
    }

    @ApiOperation(value = "获取APP版本管理列表",notes =
            "请求信息： \n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
            "返回信息： \n" +
                    "&emsp; versionno &nbsp; : &nbsp; 版本号 \n" +
                    "&emsp; versiondes &nbsp; : &nbsp; 版本描述 \n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/get")
//    @RequiresPermissions("issue")
    public Response<PageInfo<AppManageListRes>> get(@RequestBody PageInfoReq pageInfoReq){
        if (pageInfoReq.getPageNo()==null){
            pageInfoReq.setPageNo(1);
        }
        if (pageInfoReq.getPageSize()==null){
            pageInfoReq.setPageSize(10);
        }
        if (pageInfoReq.getPageNo()==null&&pageInfoReq.getPageSize()==null){
            pageInfoReq.setPageNo(1);
            pageInfoReq.setPageSize(10);
        }
        return issueService.getListAll(pageInfoReq.getPageNo(),pageInfoReq.getPageSize());
    }

    @ApiOperation(value = "导航栏搜索APP版本管理",notes =
            "请求信息： \n" +
                    "&emsp; starttime &nbsp; : &nbsp; 时间左区间 \n" +
                    "&emsp; endtime &nbsp; : &nbsp; 时间右区间 \n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
            "返回信息： \n" +
                    "&emsp; versionno &nbsp; : &nbsp; 版本号 \n" +
                    "&emsp; versiondes &nbsp; : &nbsp; 版本描述 \n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getbytab")
    @RequiresPermissions("issue")
    public Response<PageInfo<AppManageListRes>> getByTab(@RequestBody AppManageByTimeReq appManageByTimeReq) throws ParseException {
        if (appManageByTimeReq.getPageNo()==null){
            appManageByTimeReq.setPageNo(1);
        }
        if (appManageByTimeReq.getPageSize()==null){
            appManageByTimeReq.setPageSize(10);
        }
        if (appManageByTimeReq.getPageNo()==null&&appManageByTimeReq.getPageSize()==null){
            appManageByTimeReq.setPageNo(1);
            appManageByTimeReq.setPageSize(10);
        }
        return issueService.getListByTab(appManageByTimeReq.getStarttime(),appManageByTimeReq.getEndtime(),appManageByTimeReq.getPageNo(),appManageByTimeReq.getPageSize());
    }

    @ApiOperation(value = "获取APP升级操作记录列表",notes =
            "请求信息： \n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
                    "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 智能柜编号 \n" +
                    "&emsp; versionno &nbsp; : &nbsp; 版本号 \n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getapprecord")
    @RequiresPermissions("issue")
    public Response<PageInfo<AppRecordRes>> getAppRecord(@RequestBody PageInfoReq pageInfoReq){
        if (pageInfoReq.getPageNo()==null){
            pageInfoReq.setPageNo(1);
        }
        if (pageInfoReq.getPageSize()==null){
            pageInfoReq.setPageSize(10);
        }
        if (pageInfoReq.getPageNo()==null&&pageInfoReq.getPageSize()==null){
            pageInfoReq.setPageNo(1);
            pageInfoReq.setPageSize(10);
        }
        return issueService.getRecordList(pageInfoReq.getPageNo(),pageInfoReq.getPageSize());
    }

    @ApiOperation(value = "获取APP升级状态列表",notes =
            "请求信息： \n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
                    "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id \n" +
                    "&emsp; versionno &nbsp; : &nbsp; 版本号 \n" +
                    "&emsp; newversion &nbsp; : &nbsp; 当前升级的版本号 \n" +
                    "&emsp; localversion &nbsp; : &nbsp; 历史版本号 \n" +
                    "&emsp; status &nbsp; : &nbsp; 升级状态 (1成功 2失败) \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getappstatus")
    @RequiresPermissions("issue")
    public Response<PageInfo<AppStatusRes>> getAppStatus(@RequestBody PageInfoReq pageInfoReq){
        if (pageInfoReq.getPageNo()==null){
            pageInfoReq.setPageNo(1);
        }
        if (pageInfoReq.getPageSize()==null){
            pageInfoReq.setPageSize(10);
        }
        if (pageInfoReq.getPageNo()==null&&pageInfoReq.getPageSize()==null){
            pageInfoReq.setPageNo(1);
            pageInfoReq.setPageSize(10);
        }
        return issueService.getStatusList(pageInfoReq.getPageNo(),pageInfoReq.getPageSize());
    }

    @ApiOperation(value = "APP在线升级",notes =
            "请求信息： \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 智能柜编号 \n" +
                    "&emsp; version &nbsp; : &nbsp; 版本号 \n" +
                    "&emsp; issueway &nbsp; : &nbsp; 下发方式(0立即 1定时) \n" +
                    "&emsp; issuetime &nbsp; : &nbsp; 下发时间(下发方式为1定时情况下才有此参数) \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 600 &nbsp; : &nbsp; 升级错误信息  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/upgradeone")
    @MyLog(operation = "APP在线升级")
    @RequiresPermissions("issue")
    public Response upgradeOne(@RequestBody AppUpGradeOneReq appUpGradeOneReq){
        return issueService.upGradeOne(appUpGradeOneReq.getSmartno(),appUpGradeOneReq.getVersionno(),appUpGradeOneReq.getIssueway(),appUpGradeOneReq.getIssuetime());
    }

    @ApiOperation(value = "APP在线升级全部升级",notes =
            "请求信息： \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 智能柜编号(多个编号用英文,隔开) \n" +
                    "&emsp; version &nbsp; : &nbsp; 版本号 \n" +
                    "&emsp; issueway &nbsp; : &nbsp; 下发方式(0立即 1定时) \n" +
                    "&emsp; issuetime &nbsp; : &nbsp; 下发时间(下发方式为1定时情况下才有此参数) \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 600 &nbsp; : &nbsp; 升级错误信息  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/upgradeall")
    @MyLog(operation = "APP在线全部升级")
    @RequiresPermissions("issue")
    public Response upgradeAll(@RequestBody AppUpGradeOneReq appUpGradeOneReq){
        return issueService.upGradeAll(appUpGradeOneReq.getSmartno(),appUpGradeOneReq.getVersionno(),appUpGradeOneReq.getIssueway(),appUpGradeOneReq.getIssuetime());
    }

    @ApiOperation(value = "获取APP在线升级列表",notes =
            "请求信息： \n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
            "返回信息： \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 智能柜编号 \n" +
                    "&emsp; versionno &nbsp; : &nbsp; 版本号 \n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getupgradealllist")
    @RequiresPermissions("issue")
    public Response<PageInfo<AppUpGradeListRes>> getupgradeAllList(@RequestBody PageInfoReq pageInfoReq){
        if (pageInfoReq.getPageNo()==null){
            pageInfoReq.setPageNo(1);
        }
        if (pageInfoReq.getPageSize()==null){
            pageInfoReq.setPageSize(10);
        }
        if (pageInfoReq.getPageNo()==null&&pageInfoReq.getPageSize()==null){
            pageInfoReq.setPageNo(1);
            pageInfoReq.setPageSize(10);
        }
        return issueService.getAppUpGradeAllList(pageInfoReq.getPageNo(),pageInfoReq.getPageSize());
    }

    @ApiOperation(value = "导航栏搜索APP在线升级列表",notes =
            "请求信息： \n" +
                    "&emsp; versionno &nbsp; : &nbsp; 版本号 \n" +
                    "&emsp; starttime &nbsp; : &nbsp; 时间左区间 \n" +
                    "&emsp; endtime &nbsp; : &nbsp; 时间右区间 \n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
            "返回信息： \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 智能柜编号 \n" +
                    "&emsp; versionno &nbsp; : &nbsp; 版本号 \n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getupgradelistbytab")
    @RequiresPermissions("issue")
    public Response<PageInfo<AppUpGradeListRes>> getupgradeListByTab(@RequestBody AppUpGradeTabReq appUpGradeTabReq) throws ParseException {
        if (appUpGradeTabReq.getPageNo()==null){
            appUpGradeTabReq.setPageNo(1);
        }
        if (appUpGradeTabReq.getPageSize()==null){
            appUpGradeTabReq.setPageSize(10);
        }
        if (appUpGradeTabReq.getPageNo()==null&&appUpGradeTabReq.getPageSize()==null){
            appUpGradeTabReq.setPageNo(1);
            appUpGradeTabReq.setPageSize(10);
        }
        return issueService.getAppUpGradeListByTab(appUpGradeTabReq.getVersionno(),appUpGradeTabReq.getStarttime(),appUpGradeTabReq.getEndtime(),appUpGradeTabReq.getPageNo(),appUpGradeTabReq.getPageSize());
    }

    @ApiOperation(value = "APP设置取货验证码次数、解除时间",notes =
            "请求信息： \n" +
                    "&emsp; verifynum &nbsp; : &nbsp; 取货验证码次数 \n" +
                    "&emsp; verifymovetime &nbsp; : &nbsp; 取货验证码解除时间(小时) \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/verify")
    @MyLog(operation = "设置验证码次数时间")
    @RequiresPermissions("issue")
    public Response verify(@RequestBody VerifyReq verifyReq ){
        return issueService.verify(verifyReq.getVerifynum(),verifyReq.getVerifymovetime());
    }

    @ApiOperation(value = "获取APP设置取货验证码列表",notes =
            "请求信息： \n" +
                    "&emsp; pageNo &nbsp; : &nbsp;  当前页数\n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
            "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; id \n" +
                    "&emsp; verifynum &nbsp; : &nbsp; 取货验证码次数 \n" +
                    "&emsp; verifymovetime &nbsp; : &nbsp; 取货验证码解除时间(小时) \n" +
                    "&emsp; createtime &nbsp; : &nbsp; 创建时间 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getverifylist")
    @RequiresPermissions("issue")
    public Response<PageInfo<PickCode>> getVerifyList(@RequestBody PageInfoReq pageInfoReq){
        if (pageInfoReq.getPageNo()==null){
            pageInfoReq.setPageNo(1);
        }
        if (pageInfoReq.getPageSize()==null){
            pageInfoReq.setPageSize(10);
        }
        if (pageInfoReq.getPageNo()==null&&pageInfoReq.getPageSize()==null){
            pageInfoReq.setPageNo(1);
            pageInfoReq.setPageSize(10);
        }
        return issueService.getVerifyList(pageInfoReq.getPageNo(),pageInfoReq.getPageSize());
    }

    @ApiOperation(value = "APP设置修改智能柜密码",notes =
            "请求信息： \n" +
                    "&emsp; roleflag &nbsp; : &nbsp; 用户权限标志(0超级管理员 1普通管理员) \n" +
                    "&emsp; province &nbsp; : &nbsp; 省(超级管理员不传此字段) \n" +
                    "&emsp; city &nbsp; : &nbsp; 市 (超级管理员不传此字段)\n" +
                    "&emsp; area &nbsp; : &nbsp; 区 (超级管理员不传此字段)\n" +
                    "&emsp; smartno &nbsp; : &nbsp; 智能柜编号 \n" +
                    "&emsp; password &nbsp; : &nbsp; 密码 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/setpassword")
    @MyLog(operation = "修改智能柜密码")
    @RequiresPermissions("issue")
    public Response setPassword(@RequestBody SetPasswordBySmartReq setPasswordBySmartReq ){
        return issueService.setpassword(setPasswordBySmartReq.getSmartno(),setPasswordBySmartReq.getPassword(),setPasswordBySmartReq.getRoleflag(),setPasswordBySmartReq.getProvince(),setPasswordBySmartReq.getCity(),setPasswordBySmartReq.getArea());
    }

    @ApiOperation(value = "APP设置获取智能柜密码列表",notes =
            "请求信息： \n" +
                    "&emsp; pageNo &nbsp; : &nbsp; 当前页数 \n" +
                    "&emsp; pageSize &nbsp; : &nbsp; 每页的数据条数 \n" +
                    "&emsp; roleflag &nbsp; : &nbsp; 用户权限标志(0超级管理员 1普通管理员) \n" +
                    "&emsp; province &nbsp; : &nbsp; 省(超级管理员不传此字段) \n" +
                    "&emsp; city &nbsp; : &nbsp; 市 (超级管理员不传此字段)\n" +
                    "&emsp; area &nbsp; : &nbsp; 区 (超级管理员不传此字段)\n" +
            "返回信息： \n" +
                    "&emsp; id &nbsp; : &nbsp; 智能柜id \n" +
                    "&emsp; smartno &nbsp; : &nbsp; 智能柜编号 \n" +
                    "&emsp; password &nbsp; : &nbsp; 密码 \n" +
                    "&emsp; updatetime &nbsp; : &nbsp; 最近一次修改密码的时间 \n" +
                    "返回码： \n" +
                    "&emsp; 200 &nbsp; : &nbsp; 成功  \n" +
                    "&emsp; 500 &nbsp; : &nbsp; 服务器错误  ")
    @PostMapping(value = "/getsmartpassword")
    @RequiresPermissions("issue")
    public Response<PageInfo<SmartPasswordRes>> getSmartPassword(@RequestBody RoleFlagPageReq pageInfoReq ){
        if (pageInfoReq.getPageNo()==null){
            pageInfoReq.setPageNo(1);
        }
        if (pageInfoReq.getPageSize()==null){
            pageInfoReq.setPageSize(10);
        }
        if (pageInfoReq.getPageNo()==null&&pageInfoReq.getPageSize()==null){
            pageInfoReq.setPageNo(1);
            pageInfoReq.setPageSize(10);
        }
        return issueService.getsmartpasswordlist(pageInfoReq.getPageNo(),pageInfoReq.getPageSize(),pageInfoReq.getRoleflag(),pageInfoReq.getProvince(),pageInfoReq.getCity(),pageInfoReq.getArea());
    }

}
